﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using C1.Win.C1Ribbon;
using CWCS.Entity.SRM;

namespace CWCS.UI
{
    public partial class Frmlastinfo : C1RibbonForm
    {
        BLL.ConveryBLL bll = new BLL.ConveryBLL();
        public Frmlastinfo()
        {
            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)
        {
           
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            if (textBox1.Text == null || textBox1.Text.Length != 8)
            {
                MessageBox.Show("请输出正确的托盘条码！");
                return;
            }
            if (textBox2.Text == null && textBox2.Text.Length != 4)
            {
                MessageBox.Show("请输出正确的站台号！");
                return;
            }
            String[] StaStationInfo = bll.ReadStationInfo("1013");
            string[] TaskInfo = new string[8];
            for (int i = 1; i < 8; i++)
            {
                TaskInfo[i] = StaStationInfo[i];
            }
            STACommand cmd = STACommand.ReWrite;
            string msg = string.Empty;
            int result = 0;
            if (bll.GettaskInfo(bll.WareHouseID, textBox1.Text,"", textBox2.Text, "16", "2", "C", "1000", "0", "", ref msg, ref result))
            {
                bll.ShowConveryLog("WriteInfo", "站台：" + textBox2.Text + " 手动添加尾盘入库申请成功条码:" + textBox1.Text);
                TaskInfo = bll.ConvertToTaskInfo(TaskInfo, msg);

                if (result == 1 || result == 2)
                {
                    TaskInfo[7] = "0";
                    cmd = STACommand.ReWrite;
                    if (bll.WriteStationInfo(cmd, TaskInfo, textBox2.Text, 0, 22))//写入PLC信息
                    {
                        bll.ShowConveryLog("WriteInfo", "站台：" + "1013" + msg + "写入PLC成功！任务号：" + TaskInfo[0]);
                    }
                    else
                    {
                        bll.ShowConveryLog("WriteInfo", "站台：" + "1013" + msg + "写入PLC失败！任务号：" + TaskInfo[0]);
                    }
                }
                else
                {
                    bll.ShowConveryLog("Info", msg);
                }
            }
        }
    }
}
